﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations.Schema;
using System.Diagnostics;
using System.Globalization;
using System.Runtime.Serialization;
using System.Text.RegularExpressions;
using Demo.Model;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OperationPlugins.ExtensionMethods;
using OperationPlugins.Models;
using OperationPlugins.Proxies;
using OperationPlugins.Validators;

namespace Demo.UnitTest
{
    [TestClass]
    public class ProxyTest
    {

        private static void Teee(ref int x)
        {
            x = 100;
        }

        [TestMethod]
        public void ProxyTest1()
        {
            //Stopwatch timera = new Stopwatch();
            //timera.Start();
            //for (int i = 0; i < 100000000; i++)
            //{
            //    var x = ObjectFactory.GetDefaultValue(typeof(int));
            //}
            //timera.Stop();
            //var eA = timera.Elapsed;

            //Stopwatch timerb = new Stopwatch();
            //timerb.Start();
            //for (int i = 0; i < 100000000; i++)
            //{
            //    int x = (int)ObjectFactory.GetDefaultValue2(typeof(int));
            //}
            //timerb.Stop();
            //var eB = timerb.Elapsed;



            //return;
            ////Type type = typeof(Employee);

            ////Stopwatch timera = new Stopwatch();
            ////timera.Start();
            ////for (int i = 0; i < 10000000; i++)
            ////{
            ////    DateTime d = (DateTime) Activator.CreateInstance(typeof (DateTime));
            ////}
            ////timera.Stop();
            ////var eA = timera.Elapsed;

            ////Stopwatch timerb = new Stopwatch();
            ////timerb.Start();
            ////for (int i = 0; i < 10000000; i++)
            ////{            
                
            ////    DateTime d = (DateTime)FormatterServices.GetUninitializedObject(typeof(DateTime));
            ////}
            ////timerb.Stop();
            ////var eB = timerb.Elapsed;


            ////Stopwatch timer1 = new Stopwatch();
            ////timer1.Start();
            ////for (int i = 0; i < 10000000; i++)
            ////{
            ////    Employee t = (Employee)ObjectFactory.CreateInstance(type);
            ////}
            ////timer1.Stop();
            ////var e1 = timer1.Elapsed;

            ////Stopwatch timer2 = new Stopwatch();
            ////timer2.Start();
            ////for (int i = 0; i < 10000000; i++)
            ////{
            ////    Employee t = (Employee)Activator.CreateInstance(type);
            ////}
            ////timer2.Stop();
            ////var e2 = timer2.Elapsed;

            ////Stopwatch timer3 = new Stopwatch();
            ////timer3.Start();
            ////for (int i = 0; i < 10000000; i++)
            ////{
            ////    Employee t = (Employee)ObjectFactory.CreateObjectFactory(type)();
            ////}
            ////timer3.Stop();
            ////var e3 = timer3.Elapsed;

            ////Stopwatch timer4 = new Stopwatch();
            ////timer4.Start();
            ////for (int i = 0; i < 10000000; i++)
            ////{
            ////    Employee t = (Employee)ObjectFactory.CreateInstance2(type);
            ////}
            ////timer4.Stop();
            ////var e4 = timer4.Elapsed;

            ////Stopwatch timer0 = new Stopwatch();
            ////timer0.Start();
            ////for (int i = 0; i < 10000000; i++)
            ////{
            ////    Employee t = (Employee)ObjectFactory.CreateInstance3(type);
            ////}
            ////timer0.Stop();
            ////var e0 = timer0.Elapsed;

            ////return;


           

            var proxy = Proxy.GetFor<IEmployee>();
            var proxy2 = Proxy.GetFor<IEmployee>();

            ((INotifyPropertyChanged) proxy).PropertyChanged += ProxyTest_PropertyChanged;

            proxy.Salary = 134;

            var a = proxy.Salary;

            var sss = proxy.CompanyEmail;

            var clone = (proxy as ICloneable).Clone();

            int arvo = 3;
            proxy.TeeJotakin2(ref arvo, "moi", "vaan", "sinnekin");

        }

        void ProxyTest_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
        }

        //[GetPropertyValue(typeof(IEmployee), "Salary")]
        //public class X : GetPropertyValueHandler
        //{
        //    protected override object Get(object model, Type declaringType, string propertyName)
        //    {
        //        return decimal.MaxValue;
        //    }
        //}

        [GetPropertyValue(typeof(string))]
        public class z : GetPropertyValueHandler
        {
            protected override object Get(object model, Type declaringType, string propertyName)
            {
                throw new NotImplementedException();
            }
        }

    }
}
